package com.sengled.cloud.biz.union.mgt.dao.sys;


import com.sengled.cloud.biz.union.mgt.common.PageUtil;
import com.sengled.cloud.biz.union.mgt.dao.sys.provider.RoleDaoProvider;
import com.sengled.cloud.biz.union.mgt.model.po.Role;
import com.sengled.cloud.biz.union.mgt.model.vo.RoleWithRoleType;

import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface RoleDao {

    @Update("UPDATE role SET seal_mark=1 WHERE id=#{id}")
    int deleteByPrimaryKey(Long id);

    @Insert("INSERT INTO role(role_code,role_name,role_type,company_id,create_date,operator_id) " +
            "VALUES(#{roleCode},#{roleName},#{roleType}" +
            ",#{companyId},#{createDate},#{operatorId})")
    @Options(useGeneratedKeys=true, keyProperty="id", keyColumn="id")
    Long insert(Role record);

    int insertSelective(Role record);

    @Select("select id as id,role_code as roleCode,role_name as roleName," +
            "role_type as roleType,company_id as companyId," +
            "create_date as createDate,modify_date as modifyDate," +
            "operator_id as operatorId,seal_mark as sealMark,enable_mark as enableMark " +
            "from role where id = #{id}")
    Role selectByPrimaryKey(Long id);

    int updateByPrimaryKeySelective(Role record);

    @SelectProvider(type = RoleDaoProvider.class, method = "queryRoleCountSQL")
    int queryTotalRole(@Param("role") Role role);

    @Select("select count(*) from role where id <> #{role.id} and company_id = #{role.companyId} and role_code = #{role.roleCode} and seal_mark = 0 ")
    int queryTotalRoleForUpdate(@Param("role") Role role);

    @UpdateProvider(type = RoleDaoProvider.class, method = "updateRoleSQL")
    int updateByPrimaryKey(Role record);

    @Update("update role set enable_mark = #{enableMark} where id = #{id}")
    int updateEnableMark(@Param("enableMark") int enableMark,@Param("id") Long id);

    @SelectProvider(type = RoleDaoProvider.class, method = "queryRoleSQL")
    List<RoleWithRoleType> listRole(@Param("role") Role role,@Param("pageUtil") PageUtil pageUtil);
    
}